home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / PASSDK30.ZIP;1 / DISK1.ZIP / PAS / SUBS / FM / 3812A.ASM next >
Encoding:
Assembly Source File  |  1993-02-24  |  11.5 KB  |  547 lines

  1. ;$Author:   DCODY  $
  2. ;$Date:   24 Feb 1993 16:08:32  $
  3. ;$Header:   X:/sccs/fm/3812a.asv   1.8   24 Feb 1993 16:08:32   DCODY  $
  4. ;$Log:   X:/sccs/fm/3812a.asv  $
  5. ;  
  6. ;     Rev 1.8   24 Feb 1993 16:08:32   DCODY
  7. ;  moved externADDR macros around for Borland...
  8. ;  
  9. ;     Rev 1.7   03 Feb 1993 11:59:32   DCODY
  10. ;  checking splitmode,0 was changed to splitmode,1
  11. ;  
  12. ;     Rev 1.6   08 Dec 1992 16:50:28   DCODY
  13. ;  moved externADDR macro for Borlands link
  14. ;  
  15. ;     Rev 1.5   20 Oct 1992 11:10:42   DCODY
  16. ;  adjusted tiny model .data declaration
  17. ;  
  18. ;     Rev 1.4   24 Sep 1992 08:51:56   DCODY
  19. ;  changed MVGetHardware to mvGetHardware
  20. ;  
  21. ;     Rev 1.3   20 Jul 1992 11:40:56   DCODY
  22. ;  call to mvGetHWVersion requests active I/O detection.
  23. ;  
  24. ;     Rev 1.2   17 Jul 1992 13:55:46   DCODY
  25. ;  base I/O address can now move...
  26. ;  
  27. ;     Rev 1.1   27 Jun 1992 14:47:08   DCODY
  28. ;  fixed FMsplit for the opl3, and outdual3812 now programs one
  29. ;  side of the OPL3 at a time.
  30. ;  
  31. ;     Rev 1.0   26 Jun 1992 14:21:58   BCRANE
  32. ;  Initial revision.
  33. ;  
  34. ;     Rev 1.3   26 Jun 1992 14:12:08   DCODY
  35. ;  added the parameter to the gethwversion call.
  36. ;  
  37. ;     Rev 1.2   25 Jun 1992 21:11:10   DCODY
  38. ;  finished the init routine. Made timing loops variable based
  39. ;  upon the installed FM chip.
  40. ;  
  41. ;     Rev 1.1   23 Jun 1992 16:32:30   DCODY
  42. ;  PAS2 update
  43. ;  
  44. ;     Rev 1.0   15 Jun 1992 09:39:46   BCRANE
  45. ;  Initial revision.
  46. ;$Logfile:   X:/sccs/fm/3812a.asv  $
  47. ;$Modtimes$
  48. ;$Revision:   1.8  $
  49.  
  50.         Title 3812/OPL3 Access Routines
  51.  
  52. ;   /*\
  53. ;---|*|---===< 3821A.ASM >====----
  54. ;---|*|
  55. ;---|*| This is the output routine to write data to the twin 3821 chips,
  56. ;---|*| or OPL-3 4OP synth chip.
  57. ;---|*|
  58. ;---|*| Media Vision, Inc. Copyright (c) 1991,1992. All Rights Reserved.
  59. ;---|*|
  60. ;   \*/
  61.  
  62.     .xlist
  63.     include model.inc
  64.         include masm.inc
  65.     include state.inc
  66.         include target.inc
  67.     include common.inc
  68.     .list
  69.  
  70. if MODELSIZE eq 0
  71.     .code
  72. else
  73.     .data
  74. endif
  75.  
  76. if @codesize
  77.     externADDR   mvGetHWVersion
  78.     externADDR   MVInitStatePtr
  79. endif
  80.  
  81.     extrn    _MVHWVersionBits   :word
  82.     extrn    _MVTranslateCode   :word
  83.     extrn    mvhwShadowPointer  :dword
  84.  
  85. indexwrite    dw    05        ; 3812 index write delays
  86. datawrite       dw      35              ; 3812 data write delays
  87. splitmode    db    0        ; 00 = mono, 01 = stereo
  88.  
  89.     .code
  90.  
  91. ife @codesize
  92.     externADDR   mvGetHWVersion
  93.     externADDR   MVInitStatePtr
  94. endif
  95.  
  96. ;
  97. ;   /*\
  98. ;---|*|---===< mvFMInitMode (int) >====----
  99. ;---|*|
  100. ;---|*| This routine initializes the Dual 3812/OPL-3 chip
  101. ;---|*|
  102. ;---|*| Entry Conditions:
  103. ;---|*|     wParm1 = 0 to setup for mono, 1 to setup for sterero
  104. ;---|*|
  105. ;---|*| Exit Conditions:
  106. ;---|*|     AX,BX,CX,DX modified
  107. ;---|*|
  108. ;   \*/
  109.     public    mvFMInitMode
  110. mvFMInitMode    proc
  111.     push    bp
  112.     mov    bp,sp
  113. ;
  114. ; validate the hardware if not done already.
  115. ;
  116.     cmp    [_MVHWVersionBits],-1    ; check to see if we know the hardware
  117.     jnz    @F
  118.     mov    ax,USE_ACTIVE_ADDR
  119.     push    ax
  120.     call    mvGetHWVersion        ; get the hardware version
  121.     add    sp,2
  122.         cmp     al,-1                   ; everything here?
  123.     jz    mvmfexit        ; no, exit out now...
  124.     ;
  125.     @@:
  126. ;
  127. ; validate the state table pointer
  128. ;
  129.     cmp    word ptr [mvhwShadowPointer+2],0
  130.     jnz    @F
  131.     call    MVInitStatePtr
  132. ;
  133. ; setup I/O delays based upon the installed FM chip
  134. ;
  135.     test    [_MVHWVersionBits],bMVOPL3 ; defaults are setup for 3812
  136.     jz    @F               ; which are okay, exit out now...
  137.     mov    [indexwrite],3           ; OPL3 index write delays
  138.     mov    [datawrite], 3           ; OPL3 data    write delays
  139. ;
  140. @@:
  141. ;
  142. ; set the chips in mono mode, then flush them.
  143. ;
  144.     sub    ax,ax            ; set the chip(s) in mono mode
  145.     mov    splitmode,al
  146.     call    FMsplit
  147.  
  148.     mov    dx,LFMADDR        ; flush the left/right side
  149.     xor    dx,[_MVTranslateCode]    ; translate to the board address
  150.     call    flushit
  151. ;
  152. ; now, split the chips into stereo mode if requested to do so
  153. ;
  154.     cmp    wptr wParm1,0        ; all done?
  155.     jz    mvmfexit        ; yes, exit
  156.  
  157.     mov    al,1            ; split it now
  158.         mov     splitmode,al
  159.     call    FMsplit
  160. ;
  161. mvmfexit:
  162.     pop    bp
  163.         ret
  164.  
  165. mvFMInitMode    endp
  166.  
  167. ;
  168. ;   /*\
  169. ;---|*|---===< outdual3812(int,int,int) >====----
  170. ;---|*|
  171. ;---|*| This routine writes index/data to
  172. ;---|*| both chips in an interleaved fashion.
  173. ;---|*|
  174. ;---|*| Entry Conditions:
  175. ;---|*|     wParm1 is the chip index value
  176. ;---|*|     wParm2 is the left    FM chip data
  177. ;---|*|     wParm3 is the right FM chip data
  178. ;---|*|
  179. ;---|*| Exit Conditions:
  180. ;---|*|     AX,DX,CX modified
  181. ;---|*|
  182. ;   \*/
  183.  
  184.     public    outdual3812
  185. outdual3812    proc
  186. ;
  187. ; this is kinda screwy, but if we're in mono mode, don't write to both sides
  188. ;
  189.     cmp    splitmode,1        ; are we doing both?
  190.     jjnz    outleft3812        ; no, just do the left side...
  191. ;
  192. ; frame the stack and continue.
  193. ;
  194.     push    bp
  195.     mov    bp,sp
  196. ;
  197. ; write the index to both chips
  198. ;
  199.         mov     dx,LFMADDR              ; get the left 3812 address
  200.     xor    dx,[_MVTranslateCode]    ; translate to the board address
  201.         mov     al,wParm1               ; get the index value
  202. ;
  203. ; special case the OPL3 since it only really has one index register.
  204. ;
  205.     test    [_MVHWVersionBits],bMVOPL3 ; defaults are setup for 3812
  206.     jnz    outtoopl3           ; which are okay, exit out now...
  207. ;
  208. ; the dual 3812s can have interleaved I/O to speed up the pace
  209. ;
  210.     out    dx,al            ; output to both chips
  211.     add    dx,2
  212.     out    dx,al
  213. ;
  214. ; wait the proper delays for either FM chip
  215. ;
  216.     mov    cx,[indexwrite]
  217.     ;
  218.     @@:
  219.         in      al,dx
  220.     loop    @B
  221. ;
  222. ; write the data out to the chip now
  223. ;
  224.     dec    dx            ; move back to the left FM data reg
  225.     mov    al,byte ptr wParm2
  226.     mov    ah,byte ptr wParm3
  227.  
  228.     out    dx,al            ; write the data out
  229.     add    dx,2
  230.     xchg    ah,al
  231.     out    dx,al
  232. ;
  233. ; wait the proper delays for either FM chip
  234. ;
  235.     mov    cx,[datawrite]
  236.     ;
  237.     @@:
  238.     in    al,dx
  239.     loop    @B
  240.  
  241.     pop    bp
  242.     ret
  243. ;
  244. outtoopl3:
  245. ;
  246. ; do the left side of the OPL3 first
  247. ;
  248.     ; write the left index
  249.  
  250.         out     dx,al                   ; output to both chips
  251.     mov    cx,[indexwrite]
  252.     ;
  253.     @@:
  254.         in      al,dx
  255.     loop    @B
  256.  
  257.     ; write the left data
  258.  
  259.         inc     dx                      ; move to the left FM data reg
  260.     mov    al,wParm2
  261.     out    dx,al            ; write the data out
  262.     mov    cx,[datawrite]
  263.     ;
  264.     @@:
  265.     in    al,dx
  266.     loop    @B
  267. ;
  268. ; do the right side of the OPL3 next
  269. ;
  270.     ; write the right index
  271.  
  272.     inc    dx
  273.         mov     ax,wParm1               ; get the index value
  274.         out     dx,al                   ; output to both chips
  275.     mov    cx,[indexwrite]
  276.     ;
  277.     @@:
  278.         in      al,dx
  279.     loop    @B
  280.  
  281.     ; write the right data
  282.  
  283.         inc     dx                      ; move to the left FM data reg
  284.     mov    al,wParm3
  285.  
  286.     out    dx,al            ; write the data out
  287.     mov    cx,[datawrite]
  288.     ;
  289.     @@:
  290.     in    al,dx
  291.     loop    @B
  292.  
  293.     pop    bp
  294.     ret
  295.  
  296. outdual3812    endp
  297.  
  298. ;
  299. ;   /*\
  300. ;---|*|---===< outleft3812(int,int) >====----
  301. ;---|*|
  302. ;---|*| This routine writes index/data to the left FM chip.
  303. ;---|*|
  304. ;---|*| Entry Conditions:
  305. ;---|*|     wParm1 is the left FM index
  306. ;---|*|     wParm2 is the left FM chip data
  307. ;---|*|
  308. ;---|*| Exit Conditions:
  309. ;---|*|     AX,DX,CX modified
  310. ;---|*|
  311. ;   \*/
  312.  
  313.     public    outleft3812
  314. outleft3812    proc
  315.     push    bp
  316.     mov    bp,sp
  317. ;
  318. ; write the index to both chips
  319. ;
  320.         mov     dx,LFMADDR              ; get the left 3812 address
  321.     xor    dx,[_MVTranslateCode]    ; translate to the board address
  322. ;
  323. fm_common_output label near
  324. ;
  325. ; output the index to the single chip
  326. ;
  327.         mov     ax,wParm1               ; get the index value
  328.     out    dx,al            ; output to both chips
  329.     mov    cx,[indexwrite]
  330. ;
  331. @@:
  332.         in      al,dx                   ; slow down for the index to settle
  333.     loop    @B
  334.  
  335.     inc    dx            ; move to the data register
  336.  
  337.         mov     ax,wParm2
  338.     out    dx,al            ; write the data out
  339.  
  340.     mov    cx,[datawrite]
  341. ;
  342. @@:
  343.     in    al,dx
  344.     loop    @B
  345.  
  346.     pop    bp
  347.     ret
  348.  
  349. outleft3812    endp
  350.  
  351. ;
  352. ;   /*\
  353. ;---|*|---===< outright3812(int,int) >====----
  354. ;---|*|
  355. ;---|*| This routine writes index/data to the right FM chip.
  356. ;---|*|
  357. ;---|*| Entry Conditions:
  358. ;---|*|     wParm1 is the right FM index
  359. ;---|*|     wParm1 is the right FM chip data
  360. ;---|*|
  361. ;---|*| Exit Conditions:
  362. ;---|*|     AX,DX,CX modified
  363. ;---|*|
  364. ;   \*/
  365.  
  366.     public    outright3812
  367. outright3812    proc
  368.     push    bp
  369.     mov    bp,sp
  370. ;
  371. ; write the index to both chips
  372. ;
  373.     mov    dx,RFMADDR        ; get the right 3812 address
  374.         xor     dx,[_MVTranslateCode]   ; translate to the board address
  375.         jmp     short fm_common_output
  376.  
  377. outright3812    endp
  378.  
  379. ;
  380. ;--------------------------==========================--------------------------
  381. ;--------------------------====< local routines >====--------------------------
  382. ;--------------------------==========================--------------------------
  383. ;
  384.  
  385. ;
  386. ;   /*\
  387. ;---|*|---===< flushit >====----
  388. ;---|*|
  389. ;---|*| Reset both sides of the FM chip(s)
  390. ;---|*|
  391. ;---|*| Entry Conditions:
  392. ;---|*|     none
  393. ;---|*|
  394. ;---|*| Exit Conditions:
  395. ;---|*|     AX,BX,CX,DX modified
  396. ;---|*|
  397. ;   \*/
  398. ;
  399. flushit proc    near
  400.     mov    ax,1        ; reg 1
  401.     call    fmout
  402.  
  403.         inc     ax              ; reg 2
  404.     call    fmout
  405.  
  406.         inc     ax              ; reg 3
  407.     call    fmout
  408.  
  409.         inc     ax              ; reg 4
  410.     call    fmout
  411.  
  412.         mov     al,8            ; reg 8
  413.     call    fmout
  414.  
  415.         mov     al,20h          ; flush all others from reg 20 to reg FF
  416.     mov    cx,0FFh-20h
  417. ;
  418. @@:
  419.     call    fmout
  420.     inc    ax
  421.     loop    @B
  422.  
  423.     ret
  424.  
  425. flushit endp
  426.  
  427. ;
  428. ;   /*\
  429. ;---|*|---===< FMsplit >====----
  430. ;---|*|
  431. ;---|*| Split or combine the FM sides.
  432. ;---|*|
  433. ;---|*| Entry Conditions:
  434. ;---|*|     AL = 1 for stereo, 0 for mono
  435. ;---|*|
  436. ;---|*| Exit Conditions:
  437. ;---|*|     AX,BX,CX,DX modified
  438. ;---|*|
  439. ;   \*/
  440. ;
  441. FMsplit proc    near
  442. ;
  443. ; record either MONO or STEREO in the state table
  444. ;
  445.     push    es
  446.     push    di
  447.     les    di,[mvhwShadowPointer]       ; we have to record in in the state
  448. ;
  449. ; maintain the split state fact in the old split FM bit
  450. ;
  451.     mov    ah,al                 ; save an original copy
  452.     cmp    al,1                 ; set carry if zero
  453.     sbb    al,al                 ; al = FF for mono
  454.     and    al,bMImonofm             ; keep the bit if mono
  455.  
  456.         and     es:[di._audiomixr],NOT bMImonofm ; flush the bit
  457.     or    es:[di._audiomixr],al         ; maybe set it
  458.     mov    al,es:[di._audiomixr]         ; load a copy for old pas
  459.  
  460.     pop    di
  461.     pop    es
  462. ;
  463. ; if OPL3, go do it's split, else just write out the new mixer setting
  464. ;
  465.         test    [_MVHWVersionBits],bMVOPL3 ; defaults are setup for 3812
  466.     jnz    splitopl3           ; which are okay, exit out now...
  467.  
  468.     mov    dx,AUDIOMIXR           ; get the mixer address
  469.     xor    dx,[_MVTranslateCode]       ; translate to the board address
  470.     out    dx,al               ; send the bits out to the h/w
  471.  
  472.         ret
  473. ;
  474. splitopl3:
  475.     mov    al,5               ; send it to the right FM reg 5
  476.     mov    dx,RFMADDR
  477.         xor     dx,[_MVTranslateCode]      ; translate to the board address
  478.     out    dx,al               ; send the index
  479.  
  480.         mov     cx,[indexwrite]
  481.     ;
  482.     @@:
  483.     in    al,dx               ; wait the prescribed period
  484.     loop    @B
  485.  
  486.     inc    dx
  487.         mov     al,ah
  488.     out    dx,al               ; send the data byte
  489.  
  490.         mov     cx,[datawrite]
  491.     ;
  492.     @@:
  493.     in    al,dx               ; wait the prescribed period
  494.     loop    @B
  495.  
  496.         ret
  497.  
  498. FMsplit endp
  499.  
  500. ;
  501. ;   /*\
  502. ;---|*|---===< fmout >====----
  503. ;---|*|
  504. ;---|*| write to one of the chips.
  505. ;---|*|
  506. ;---|*| Entry Conditions:
  507. ;---|*|     DX holds the base address (left side or right side)
  508. ;---|*|     AL holds the index register value
  509. ;---|*|     AH holds the data  register value
  510. ;---|*|
  511. ;---|*| Exit Conditions:
  512. ;---|*|     no registers modified
  513. ;---|*|
  514. ;   \*/
  515. ;
  516. fmout   proc    near
  517.     push    ax
  518.     push    cx
  519.  
  520.     out    dx,al
  521.     mov    cx,[indexwrite]
  522. ;
  523. @@:
  524.     in    al,dx
  525.     loop    @B
  526.  
  527.     xchg    ah,al
  528.     inc    dx
  529.     out    dx,al
  530.  
  531.         mov     cx,[datawrite]
  532. ;
  533. @@:
  534.     in    al,dx
  535.     loop    @B
  536.  
  537.     dec    dx
  538.  
  539.     pop    cx
  540.     pop    ax
  541.     ret
  542.  
  543. fmout    endp
  544.  
  545.         end
  546.  
  547.